package com.atguigu.ssyx.common.config;

import com.atguigu.ssyx.enums.ActivityType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;


@Component
public class StringActivityTypeCoverter implements Converter<String, ActivityType> {
    @Override
    public ActivityType convert(String code) {

        //ActivityType.values() 拿到全部实例对象
        for (ActivityType activityType : ActivityType.values()) {
            //判断枚举的code是否和前端传递过来的值相等
            if (activityType.getCode().equals(Integer.valueOf(code))) {
                //相等就返回枚举对象
                return activityType;
            }
        }
        throw new RuntimeException("code非法");
    }


}
